﻿using Hello.Api.Contracts;
using MassTransit;

namespace Hello.Api.Consumers
{
    //消息者的配置项都定义在Defination中
    public class MessageConsumerDefination : ConsumerDefinition<MessageConsumer>
    {
        public MessageConsumerDefination()
        {
            Endpoint(x => x.Name = "message.consumer");//配置消费者端点，会覆盖全局配置
        }
        protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, 
            IConsumerConfigurator<MessageConsumer> consumerConfigurator
            ,IRegistrationContext context)
        {
            consumerConfigurator.ConcurrentMessageLimit = 2;//并发数
            //consumerConfigurator.UseMessageRetry(x => x.Interval(5, TimeSpan.FromSeconds(3)));//重试次数及间隔
            consumerConfigurator.UseCircuitBreaker(cb => { 
                cb.TrackingPeriod= TimeSpan.FromSeconds(3);
                cb.TripThreshold = 15;
                cb.ActiveThreshold = 10;
                cb.ResetInterval=TimeSpan.FromMinutes(5);
            });
        }
    }
}
